<template>
  <div>
    <Card>
      <div class="p-relative">
        <div @click="refresh" class="p-absolute refresh-btn">
          <Icon size='24' type="md-refresh" />
        </div>
        <div class="flex-box search-area">
          <div class="flex-item search-btn">
            <Button type="warning" @click='create'>添加开课课程</Button>
          </div>
          <div class="flex-item">
            <Input v-model="searchObj.name" placeholder="请输入名称"></Input>
          </div>
          <div class="flex-item">
          <Date-picker v-model="searchObj.use_time"  type="date" confirm placeholder="选择日期" style="width: 200px"  @on-change="changDate"></Date-picker>

          </div>

          <div class="flex-item search-btn" @click="search">
            <Button type="warning">搜索</Button>
          </div>
          <div class="flex-item search-btn" @click="reset">
            <Button>重置</Button>
          </div>

        </div>
      </div>

      <Table :columns="tableOption" :data="data.list" border :no-data-text="loadingText ? loadingText : '暂无数据'" border
        ref="tables" editable search-place="top">
        <template slot-scope="{ row, index }" slot="start_time">
          {{row.start_time}} - {{row.end_time}}
        </template>
         <template slot-scope="{ row, index }" slot="estate">
            <div v-if="row.estate == 0">
                预约中
            </div>
            <div v-else-if="row.estate == 1">
                已开课
            </div>
            <div v-else="row.estate == 8">
                停用
            </div>
        </template>

        <template slot-scope="{ row, index }" slot="revenue_count">
           <Button type='warning' @click="getStudentList(row, index,1)" size='small'>查看</Button>
        </template>
         <template slot-scope="{ row, index }" slot="real_count">
           <Button type='warning' @click="getStudentList(row, index,2)" size='small'>查看</Button>
        </template>
        <template slot-scope="{ row, index }" slot="coach_name">
           <Button type='warning' @click="setCoach(row, index)" size='small'>设置</Button>
        </template>
        <template slot-scope="{ row, index }" slot="status">
             <i-switch  v-model="row.status" @on-change="changeEstate($event,row.expand_id)" style="width:50px;">
                <span slot="open">启用</span>
                <span slot="close">禁用</span>
            </i-switch>
        </template>
        <template slot-scope="{ row, index }" slot="action">
          <div class="flex-box flex-center flex-margin">
            <!-- <Button type='warning' @click="edit(row, index)" size='small'>编辑</Button> -->
            <Button type='error' @click="del(row, index)" size='small'>删除</Button>

          </div>
        </template>
      </Table>
      <Page class="foot-page" :current='page.current' :total="page.total" :page-size="page.pageSize" show-total
        show-elevator @on-change="changepage"></Page>

    </Card>

    <!-- 添加弹窗 -->
    <Modal v-model="createModal" :title="createTitle" width='900'>

         <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
                  <FormItem label="课程产品" >

                    <Select @on-change="selectProduct($event)"  v-model="formValidate.product_id" style="width:200px" filterable placeholder='请选择课程'  >
                        <Option  v-for="(item,index) in data.productCourse" :value="item.id" :key="index"   >{{item.name}} </Option>
                  </Select>

                </FormItem>
                <FormItem label="机构" >

                    {{formValidate.organ_name}}

                </FormItem>
                <FormItem label="门店"   prop="store_id">

                    <Select v-model="formValidate.store_id"  placeholder='请选择门店'  filterable  multiple>
                        <Option v-for="(item,index) in data.storeList"  :value="item.id" :key="index">{{item.name}} </Option>
                  </Select>

                </FormItem>


                 <FormItem label="教练"   prop="coach">
                    <Checkbox-group v-model="formValidate.coach_id">
                      <Checkbox  v-for="(item,index) in data.coach" :label="item.id" :key="index">{{item.name}}</Checkbox>


                  </Checkbox-group>


                </FormItem>
               <!--  <FormItem label="球类"  prop="ball_property_id">

                    <Select v-model="formValidate.ball_property_id" style="width:130px" placeholder='请选择球类' >
                        <Option v-for="(item,index) in data.ballProperty" :value="item.id" :key="index">{{item.name}} </Option>
                  </Select>

                </FormItem> -->


                 <FormItem label="开课时间" prop="use_time">
                  <Date-picker v-model="formValidate.use_time" type="daterange" placeholder="选择日期" style="width: 200px"  @on-change="useTimeChange"></Date-picker>


                </FormItem>
                 <FormItem label="开课星期"   prop="">
                    <Checkbox-group v-model="formValidate.week">
                          <Checkbox label="1">星期一</Checkbox>
                          <Checkbox label="2">星期二</Checkbox>
                          <Checkbox label="3">星期三</Checkbox>
                          <Checkbox label="4">星期四</Checkbox>
                          <Checkbox label="5">星期五</Checkbox>
                          <Checkbox label="6">星期六</Checkbox>
                          <Checkbox label="7">星期日</Checkbox>


                  </Checkbox-group>


                </FormItem>
              <FormItem label="选择模板"  >
                <div class="flex-start-box">
                  <Select v-model="formValidate.course_model_id" @on-change="modelIdChange()" placeholder="请选择模板" style="width:200px;" >

                    <Option :value="item.id" v-for="(item,index) in data.courseModelList">{{item.name}}</Option>
                  </Select>
                </div>

              </FormItem>
                 <FormItem label="设置模板" >
                  <Button type="warning" @click="setModel()"  >设置模板</Button>
                </FormItem>



            </Form>






      <div slot="footer">
        <Button type="warning" @click="save('formValidate')" :disabled="isDisable" :loading="isLoading">保存</Button>
      </div>
    </Modal>




    <Modal v-model="uploadModal" title="图片管理" class="uploadModal-wrap" :closable='isClosable'>
      <!-- 上传组件 -->
      <div>
        <UploadTool :showUpload='showUpload' :optionObj='uploadImgPathList' @getSelectedImgList='getSelectedImgList'>
        </UploadTool>
      </div>
      <div slot="footer">
        <Button @click='cancelUploadModal'>取消</Button>
        <Button type="primary" @click='confirm(uploadType)'>确定</Button>
      </div>
    </Modal>



    <!-- 删除弹窗 -->
    <Modal v-model="delModal" title="提示" width="250">
      <p class="font16">
        <Icon class='del-tips-icon' type="ios-alert-outline" color='orange' size='22' />确定删除该数据吗？
      </p>
      <div slot="footer">
        <Button @click='delModal=false'>取消</Button>
        <Button type="primary" @click='confirmDel'>确定</Button>
      </div>
    </Modal>

    <!-- 修改授课教练弹窗 -->
    <Modal v-model="coachModal" title="修改授课教练" width="250" type='cneter'>
        <div>
            教练：
            <Checkbox-group v-model="coach_ids" >
                <Checkbox  v-for="(item,index) in coachList" :label="item.id" :key="index">{{item.name}}</Checkbox>


            </Checkbox-group>
        </div>


      <div slot="footer">
        <Button @click='coachModal=false'>取消</Button>
        <Button type="primary" @click='editCoachs'>确定</Button>
      </div>
    </Modal>
    <!-- 学员列表弹窗 -->
    <Modal v-model="studentModal" title="学员列表" width="800">
      <Card>
      <div class="p-relative">

        <div class="flex-box search-area">
         <!--  <div class="flex-item search-btn">
            <Button type="warning" @click='create'>添加开课课程</Button>
          </div> -->
         <!--  <div class="flex-item">
            <Input v-model="searchObj.name" placeholder="请输入名称"></Input>
          </div>

          <div class="flex-item search-btn" @click="search">
            <Button type="warning">搜索</Button>
          </div>
 -->

        </div>
      </div>

      <Table :columns="userOption" :data="data.studentList" border :no-data-text="loadingText ? loadingText : '暂无数据'" border
        ref="tables" editable search-place="top">




        <template slot-scope="{ row, index }" slot="action">
          <div class="flex-box flex-center flex-margin">
            <!-- <Button type='warning' @click="edit(row, index)" size='small'>编辑</Button> -->
            <!-- <Button type='error' @click="del(row, index)" size='small'>删除</Button> -->

          </div>
        </template>
      </Table>
      <Page class="foot-page" :current='page.currentStudent' :total="page.totalStudent" :page-size="page.pageSizeStudent" show-total
        show-elevator @on-change="changepageStudent"></Page>

    </Card>
      <div slot="footer">
      <!--   <Button @click='delModal=false'>取消</Button>
        <Button type="primary" @click='confirmDel'>确定</Button> -->
      </div>
    </Modal>


     <!-- 价格模板 -->
    <Modal v-model="weekPriceModal" title="开课模板" width='1200'>

        <Tabs  :value="tabsName">
           <!-- <TabPane :label="item.name" :name="'ball_property_'+item.id" v-for="(item,index) in checkboxPropert"> -->
          <TabPane label="开课模板" :name="tabsName" >

              <div class="fee-box" style="width: 98%;">
                <div class="fee-head"> <span>批量设置</span>
                  <Button type="warning" class="fee-add" size="small" @click='batchInsert'>新增</Button>
                  <Button type="info" class="fee-batch" size="small" @click='batchSet'>批量设置</Button>
                </div>
                <div style="padding:5px 15px  ">
                  <Row :gutter="16" v-for="(item,index) in batchLen">
                    <Col span="5">
                    <TimePicker type="timerange"    :disabled-hours="[0,1,2,3,4,5,6,7]" hide-disabled-options format="HH:mm"
                      @on-change="batchAddTime($event,index)" placeholder="请选择时间段" style="width: 100%"> </TimePicker>
                    </Col>
                    <Col span="5">
                    <Input @on-keyup="batchAddAmount($event,index)"   type="number" placeholder="请设置价格"> <span
                      slot="append">元</span></Input>

                    </Col>
                    <Col span="5">
                    <Input @on-keyup="batchAddNum($event,index)"   type="number" placeholder="请设置消费小时"> <span
                      slot="append">时</span></Input>

                    </Col>

                  </Row>
                </div>
              </div>

              <!-- 一周价格表格 -->
              <div class="flex-box flex-fee" style="overflow-y: auto; height: 600px;" >
                <div class="fee-box" v-for="(item,index) in weekArr">
                  <div class="fee-head"> <span>{{item.name}}</span>
                    <Button type="warning" class="fee-add" size="small" @click='weekInsert(item,index)'>新增</Button>
                  </div>
                  <div style="padding:5px 15px  ">

                    <Row :gutter="16" v-if="item.time_range.length>0" v-for="(row,j) in item.time_range">
                      <Col span="8">
                      <TimePicker type="timerange" :disabled-hours="[0,1,2,3,4,5,6,7]" hide-disabled-options format="HH:mm"
                        @on-change="weekAddTime($event,item,index,j)" v-if="item.time_range.length==0" placeholder="请选择时间段"
                        style="width: 100%">
                      </TimePicker>
                      <TimePicker type="timerange" :disabled-hours="[0,1,2,3,4,5,6,7]" hide-disabled-options format="HH:mm"
                        @on-change="weekAddTime($event,item,index,j)" v-if="item.time_range.length>0" :value="row.time"
                        placeholder="请选择时间段" style="width: 100%">
                      </TimePicker>

                      </Col>
                      <Col span="8">
                        <Input @on-keyup="weekAddAmount($event,item,index,j)" v-if="item.time_range.length==0" type="number"
                        placeholder="请设置价格"> <span slot="append">元</span></Input>
                        <Input @on-keyup="weekAddAmount($event,item,index,j)" v-if="item.time_range.length>0" :value="row.price"
                        type="number" placeholder="请设置价格"> <span slot="append">元</span></Input>

                      </Col>
                      <Col span="6">

                        <Input @on-keyup="weekAddNum($event,item,index,j)" v :value="row.num"
                        type="number" placeholder="请设置耗时"> <span slot="append">时</span></Input>

                      </Col>
                      <Col span="2">


                        <Button type="warning" class="fee-add" size="small" @click='weekDel(item,index,j)'>删除</Button>
                      </Col>

                    </Row>
                  </div>
                </div>
              </div>

           </TabPane>
        </Tabs>

    </Modal>




  </div>
</template>
<!-- 公共弹框，成功，失败，报错，loading -->
<script>
  import {
    mapState,
    mapMutations
  } from 'vuex'
  // 接口
  import {
    getList,
    add,
    put,
    del,
    setEstate,
    editCoach,
    getStudentList,

  } from '@/api/product-group/course-manage'
  import {
    tableOption,
    coachCardOption,
    userOption,
  } from '../../../data/product-group/course-manage.js'
  import Tables from '_c/tables'
   import {
    permission
  } from '@/config/permission.js'
  import 'quill/dist/quill.core.css'
  import 'quill/dist/quill.snow.css'
  import 'quill/dist/quill.bubble.css'
  import {
    quillEditor,
    Quill
  } from 'vue-quill-editor'
  import {
    uploadImgPathList
  } from '@/config/global.js'

  // 上传组件
  import UploadTool from '../../components/uploadTool/uploadTool.vue'
   import ImageResize from 'quill-image-resize-module'

  Quill.register('modules/imageResize', ImageResize);
  export default {
    name: 'tables_page',
    components: {
      Tables,
      quillEditor,
      UploadTool
    },
    created() {
      let _this = this
      this.$nextTick(function() {
        // 权限校验
        _this.role_add = permission(this.roles, 'coach/add')
        _this.role_edit = permission(this.roles, 'coach/edit')
        _this.role_del = permission(this.roles, 'coach/del')

      })
      // console.log(_this.role_add)

      this.getList()
    },
    watch: {

    },
    mounted() {

    },
    computed: {
      ...mapState({
        prodGroupBasicObj: state => state.share.prodGroupBasicObj,
        roles: state => state.user.roles

      }),
    },
    data() {
       // 工具栏配置
      const toolbarOptions = [
        ['bold', 'italic', 'underline', 'strike'], // 加粗，斜体，下划线，删除线
        ['blockquote', 'code-block'], // 引用，代码块

        [{
          header: 1
        }, {
          header: 2
        }], // 标题，键值对的形式；1、2表示字体大小
        [{
          list: 'ordered'
        }, {
          list: 'bullet'
        }], // 列表
        [{
          script: 'sub'
        }, {
          script: 'super'
        }], // 上下标
        [{
          indent: '-1'
        }, {
          indent: '+1'
        }], // 缩进
        [{
          direction: 'rtl'
        }], // 文本方向

        [{
          size: ['small', false, 'large', 'huge']
        }], // 字体大小
        [{
          header: [1, 2, 3, 4, 5, 6, false]
        }], // 几级标题

        [{
          color: []
        }, {
          background: []
        }], // 字体颜色，字体背景颜色
        [{
          font: []
        }], // 字体
        [{
          align: []
        }], // 对齐方式

        ['clean'], // 清除字体样式
        ['image', 'video'] // 上传图片、上传视频
      ]
      let self = this;
      return {
        editorOption: {
          modules: {
            //imageDrop: true,
            imageResize: {
              displayStyles: {
                backgroundColor: "black",
                border: "none",
                color: "white"
              },
              modules: ["Resize", "DisplaySize", "Toolbar"]
            },

            toolbar: {
              container: toolbarOptions, // 工具栏
              handlers: {
                'image': function(val) {
                  console.log(val)
                  if (val) {
                    self.upload('remark')
                    // document.querySelector('.editor-upload').click()

                  } else {
                    this.quill.format('image', false); //禁用quill内部上传图片
                  }

                }

              }
            }
          }
          // some quill options
        },
        // 权限标识
        role_add: false,
        role_edit: false,
        role_del: false,


        // 上传
        // 子组件传递过来
        isClosable: false,
        previewImgModal: false,
        uploadType: '', // 上传按钮判断
        uploadIndex: 0,
        fromChild: {
          selectedImgList: [],
          week_range:'',
        },
        studentModal:false,
        coachModal:false,
        uploadModal: false,
        showUpload: false,
        uploadImgPathList: uploadImgPathList,
        // 上传
        tableOption: tableOption,
        userOption:userOption,
        userModal:false,
        delId: '',
        data: {
          list: [],
          storeList:[],
          ballProeprty:[],
          coach:[],
          productCourse:[],
          courseModelList:[],
          studentList:[],
        },

        coachList:[],
        coach_ids:[],
        editId:0,


        createTitle: '新增课程',
        isAdd: true, // 新增true,修改false
        isDisable: false, // 新增时提交按钮点击状态
        isLoading: false, // 新增时提交按钮loading状态

        loadingText: '',
        loadingUserText:'',
        tableData: [],

         weekPriceModal:false,
         batchLen: 1,
        tabsName:'card_model',
        weekArr: [],
        batchTime:[],
        batchAmount:[],
        batchNum:[],
        weekObj:[],

        // 查询参数
        searchObj: {
          name: '',
          use_time:''
        },
        // 分页
        page: {
          pageSize: 8,
          current: 1,
          total: 0,
          pageSizeStudent: 8,
          currentStudent: 1,
          totalStudent: 0
        },
        uploadList: [],
        // 分页end
        // 弹窗状态
        createModal: false, // 新增，修改弹窗
        delModal: false, // 删除弹窗


        formValidate: {
          name: '',
          class_hour: '',
          estate: 1,
          fit_member: '',
          coach_name: '0',
          cover_image: [],
          album_image: [],
          store_id:[],
          price:0,
          number:'',
          date_range:'',
          week_range:[],
          time_range:'',
          time_range:'',
          remark:'',
          sorter:0,
          is_home:0,

        },

        ruleValidate: {
          name: [{
            required: true,
            message: '请输入名称',
            trigger: 'blur'
          }],

          store_id: [{
            required: true,
            message: '请选择门店',
            type:'array',
            trigger: 'blur'
          }],


        },
        delImgItem: [],
      }
    },
    methods: {
      // 列表数据
      getList() {
        let _this = this
        let params = {
          page: this.page.current,
          size: this.page.size,
          name: this.searchObj.name,
          use_time:this.searchObj.use_time
        }

        getList(params).then(res => {
          let result = res.data.data
          if (res.data.status == 1) {

            _this.data.list = result.list
            _this.data.storeList = result.storeList
            _this.data.coach =result.coach
            _this.data.ballProperty = result.ballProperty
            _this.data.productCourse =result.productCourse
            _this.data.courseModelList = result.courseModelList
            _this.searchObj.use_time = result.use_time
            _this.page.total = result.total
            _this.page.pageSize = result.size
          } else {
             _this.data.storeList = result.storeList
            _this.data.coach =result.coach
            _this.data.ballProperty = result.ballProperty
            _this.data.productCourse =result.productCourse
            _this.data.courseModelList = result.courseModelList
            _this.searchObj.use_time = result.use_time
            let config = {
              content: res.data.message,
              background: true
            }
            _this.$Message.error(config)
          }
        }).catch(function(error) {
          // 异常
          console.log(error)
        })
      },
      checkUser(){

        this.userModal = true

      },
      changeStore(){
        // this.formValidate.product_id = '';
      },
      useTimeChange(e){

        this.formValidate.use_time = e
      },
      startTimeChange(e){
        console.log(e)
        this.formValidate.start_time = e
        console.log(this.formValidate.start_time)
      },
     endTimeChange(e){
        console.log(e)
        this.formValidate.end_time = e
         console.log(this.formValidate.end_time)
      },
      selectProduct(e){
        console.log(e,'*******')
        let _this = this
        this.data.productCourse.forEach(function(item){
            if(e == item.id){
              // this.formValidate.name =item.name
              _this.formValidate.organ_name = item.organ_name
              _this.data.storeList = item.store
              _this.data.coach =item.coach
            }
        })

      },
      checkCoach(row){
        this.formValidate.user_id = row.id
        this.formValidate.name = row.username
        this.userModal = false;

      },
      checkStore(e){
        console.log(e)
      },

      changeEstate(e,id){
        let _this = this
        let status = e?1:2;
        let obj = {
            id:id,
            status:status,
        }
        // 修改接口
          setEstate(obj).then(res => {

            if (res.data.status == 1) {


              _this.getList() // 重新刷新数据
              _this.$Message.success('操作成功')
            } else {

            }
          }).catch(function(error) {
            // 异常
            console.log(error)
          })

      },
        changeIsHome(status){
             this.formValidate.is_home = status ? true : false

        },
      //上传图片过大提示
      handleMaxSize(file) {
        let msg = '图片' + file.name + '，超出了允许上传的10M大小'
        this.$Message.error(msg)
      },
      previewImg() {
        this.previewImgModal = true
      },
      delImg(index,type) {
        if(type == 'cover'){
            this.prodGroupBasicObj.cover_image= '';
            this.prodGroupBasicObj.cover_image_file_name = ''
            this.prodGroupBasicObj.cover_image_type = ''
            this.formValidate.cover_image = ''

        }else if(type=='album'){
             this.prodGroupBasicObj.album_imageArr.splice(index, 1);
            this.formValidate.images.splice(index, 1);
        }

      },
      changepage(e) {
        this.page.current = e
        this.getList()
      },
      changepageStudent(e){
        this.page.currentStudent = e
        this.getStudentList()
      },
      changeUserPage(e){
         this.page.user_current = e

      },
      // 上传
      upload(type, index) {
        // type为上传的类型，‘cover’封面
        this.uploadModal = true
        this.showUpload = true
        this.uploadType = type
        this.uploadIndex = index
      },
      getSelectedImgList(e) {
        this.fromChild.selectedImgList = e
      },
      cancelUploadModal() {
        this.uploadModal = false
        this.showUpload = false
      },
      confirm(type) {
        console.log(type)
        let _this = this
         if (type == 'cover') {
          // 封面
          _this.formValidate.cover_image ='';
          // console.log(this.fromChild.selectedImgList)
          //   let obj = this.prodGroupBasicObj;
          //   obj.cover_image = this.fromChild.selectedImgList.map((res => {
          //     _this.formValidate.cover_image.push(res.path_name);
          //     return {
          //       url: res.url,
          //       extension: res.extension,
          //       file_name: res.path_name
          //     }
          //   }))
          let obj = this.prodGroupBasicObj;
          obj.cover_image = this.fromChild.selectedImgList[0].url;
          obj.cover_image_type = this.fromChild.selectedImgList[0].extension;
          obj.cover_image_file_name = this.fromChild.selectedImgList[0].path_name;
           _this.formValidate.cover_image = this.fromChild.selectedImgList[0].path_name;
           // console.log(_this.formValidate.cover_image)
          // this.setProdGroupBasicObj(obj)
          // console.log(_this.prodGroupBasicObj);
        } else if (type == 'album') {
            _this.formValidate.album_image = [];
            let obj = this.prodGroupBasicObj;
            obj.album_imageArr = this.fromChild.selectedImgList.map((res => {
              _this.formValidate.album_image.push(res.path_name);
              return {
                url: res.url,
                extension: res.extension,
                file_name: res.path_name
              }
            }))
            // console.log( _this.formValidate.album_image)
        }else if(type == 'remark'){

           let quill = this.$refs.myQuillEditor.quill;
          this.fromChild.selectedImgList.forEach(function(cv) {
            let length = quill.selection.savedRange.index
            // 插入图片
            quill.insertEmbed(length, 'image', cv.url)
            //quill.insertEmbed(length, 'video', url)
            // 调整光标到最后
            quill.setSelection(length + 1)

          })
          console.log('remark:', this.fromChild.selectedImgList)
          this.uploadModal = false;
          this.showUpload = false;
        }
        this.uploadModal = false
      },
      // 新增
      create() {
        console.log(this.role_add)
        // if (!this.role_add) {
        //   let config = {
        //     content: '您没有操作权限',
        //     background: true
        //   }
        //   this.$Message.error(config)
        //   return
        // }
        this.createModal = true

        this.createTitle = '新增开课课程'
        this.isAdd = true
        this.formValidate = {} // 表单重置
        this.formValidate.estate = 1;
        // this.prodGroupBasicObj.album_imageArr = {}
        //  this.prodGroupBasicObj.cover_image = ''
        this.handleReset('formValidate') // 验证重置
      },
      // 修改
      edit(row) {
        // if (!this.role_edit) {
        //   let config = {
        //     content: '您没有操作权限',
        //     background: true
        //   }
        //   this.$Message.error(config)
        //   return
        // }
        this.createModal = true
        this.createTitle = '编辑开课课程'
        this.isAdd = false
        this.formValidate = {} // 表单重置
        this.formValidate = JSON.parse(JSON.stringify(row))
        // console.log(this.formValidate)
        this.prodGroupBasicObj.album_imageArr = this.formValidate.album_imageArr||[]

         this.prodGroupBasicObj.cover_image = this.formValidate.cover_imageArr[0]['url']
        // this.formValidate.cancel_time = this.formValidate.cancel_time.toString()
        this.handleReset('formValidate') // 验证重置
      },
      setCoach(row, index){
        this.coachModal = true
        this.editId = row.course_manage_id
        this.coach_ids = row.coach_id
        this.coachList = row.coachList
      },
      getStudentList(row, index,type){
         let _this = this
        let obj = {
          id:row.id,
          page: this.page.currentStudent,
          size: this.page.sizeStudent,
          name: this.searchObj.name,
          type:type

        }
        getStudentList(obj).then(res => {
          if (res.data.status == 1) {
            _this.data.studentList = res.data.data.list
             _this.page.totalStudent = res.data.data.total
            _this.page.pageSizeStudent = res.data.data.size
            _this.studentModal = true
            // _this.$Message.success('操作成功')
            // _this.getList() // 重新刷新数据
          } else {
            // _this.delModal = false
             _this.$Message.error(res.message)
          }
        }).catch(function(error) {
          // 异常
          // _this.coachModal = false
          console.log(error)
        })
      },
      // 更改开课教练
      editCoachs(){
        let _this = this
        console.log(12321231231)
        let obj = {
          id: this.editId,
          coach_id:this.coach_ids
        }
        editCoach(obj).then(res => {
          if (res.data.status == 1) {

            _this.coachModal = false
            _this.$Message.success('操作成功')
            _this.getList() // 重新刷新数据
          } else {
            // _this.delModal = false
             _this.$Message.error(res.message)
          }
        }).catch(function(error) {
          // 异常
          _this.coachModal = false
          console.log(error)
        })
      },
      // 删除
      del(row) {
        // if (!this.role_del) {
        //   let config = {
        //     content: '您没有操作权限',
        //     background: true
        //   }
        //   this.$Message.error(config)
        //   return
        // }
        this.delId = row.id
        this.delModal = true

        // 删除接口
      },
      confirmDel() {
        let _this = this
        let obj = {
          id: this.delId
        }
        del(obj).then(res => {
          if (res.data.status == 1) {

            _this.delModal = false
            _this.$Message.success('操作成功')
            _this.getList() // 重新刷新数据
          } else {
            _this.delModal = false

          }
        }).catch(function(error) {
          // 异常
          _this.delModal = false
          console.log(error)
        })
      },
      // 刷新
      refresh() {
        this.searchObj = {} // 清空搜索框
        this.getList()
      },
      // 重置
      reset() {
        this.searchObj = {} // 清空搜索框
        this.getList()
      },
      // 查询
      search() {
        this.page.current =1
        this.getList()
      },
      changDate(e){
        // console.log(e)
        this.searchObj.use_time = e
      },
      searchUser(){
        this.page.user_current =1

      },
      save(name) {

        let _this = this
        console.log(_this.formValidate)
        this.$refs[name].validate((valid) => {
          if (valid) {
            if (_this.isAdd) {
                // console.log(_this.formValidate)
              // 新增\
               // console.log(_this.formValidate.cover_image)
              let obj = {
                     product_id: _this.formValidate.product_id,
                    store_id:_this.formValidate.store_id,
                    coach_id: _this.formValidate.coach_id,
                    ball_property_id:_this.formValidate.ball_property_id,
                    use_time: _this.formValidate.use_time,
                    start_time: _this.formValidate.start_time,
                    end_time: _this.formValidate.end_time,
                    price:_this.formValidate.price,
                    num:_this.formValidate.num,
                    week:_this.formValidate.week,
                    weekObj:this.weekObj,



              }

              // 新增接口
              add(obj).then(res => {
                if (res.data.status == 1) {
                  _this.prodGroupBasicObj.album_imageArr = {};
                  _this.createModal = false
                  _this.searchObj.use_time = ''
                  _this.getList() // 重新刷新数据
                  _this.$Message.success('操作成功')
                } else {
                  _this.createModal = false
                  // axios响应拦截
                }
              }).catch(function(error) {
                // 异常
                _this.createModal = false
                console.log(error)
              })
            } else {
              // 修改

              let obj = {
                    id:_this.formValidate.id,
                      name: _this.formValidate.name,
                    product_id: _this.formValidate.product_id,
                    store_id:_this.formValidate.store_id,
                    coach_id: _this.formValidate.coach_id,
                    ball_property_id:_this.formValidate.ball_property_id,
                    use_time: _this.formValidate.use_time,
                    start_time: _this.formValidate.start_time,
                    end_time: _this.formValidate.end_time,
                    price:_this.formValidate.price,
                    num:_this.formValidate.num,
              }

              // 修改接口
              put(obj).then(res => {
                if (res.data.status == 1) {
                  _this.prodGroupBasicObj.album_imageArr = {};
                  _this.createModal = false
                  _this.getList() // 重新刷新数据
                  _this.$Message.success('操作成功')
                } else {

                }
              }).catch(function(error) {
                // 异常
                console.log(error)
              })
            }

          } else {
            this.$Message.error('请输入必填项!')
          }
        })
      },
      handleReset(name) {
        this.$refs[name].resetFields()
      },
       onEditorBlur(quill) {


      },
      onEditorFocus(quill) {


      },
      onEditorReady(quill) {

      },
      onEditorChange({
        quill,
        html,
        text
      }) {

        this.formValidate.remark=this.escapeStringHTML(html)


      },

      escapeStringHTML(str) {
        // 转码
        str = str.replace(/&lt;/g, '<');
        str = str.replace(/&gt;/g, '>');
        return str;
      },

       modelIdChange(){
        let _this =this
        _this.data.courseModelList.forEach(function(item){
            if(item.id == _this.formValidate.course_model_id){
                _this.weekObj=_this.weekArr = item.weekObj
                // _this.formValidate.ball_property_id = item.ball_property_id
            }
        })
        console.log(_this.weekObj)
      },

      // 批量设置 star
      setModel(){
        this.weekPriceModal =true
      },

       weekInsert(item, i) {
        let data = {
          time: [],
          price: ''
        }
        item.time_range.push(data);
        this.weekArr[i] = item;
        this.weekObj[this.tabsName] = this.weekArr;
      },
       returnWeekArr() {
        let tempWeekArr = [{
            name: '周一',
            week: 1,
            time_range: [],

          },
          {
            name: '周二',
            week: 2,
            time_range: [],

          },
          {
            name: '周三',
            week: 3,
            time_range: [],

          },
          {
            name: '周四',
            week: 4,
            time_range: [],

          },
          {
            name: '周五',
            week: 5,
            time_range: [],

          },
          {
            name: '周六',
            week: 6,
            time_range: [],

          },
          {
            name: '周日',
            week: 7,
            time_range: [],

          },

        ];

        return tempWeekArr;
      },
      batchAddTime(e, i) {

        this.batchTime[i] = e
        console.log(e)
        console.log(i)

      },
      batchAddAmount(e, i) {

        this.batchAmount[i] = e.target.value
      },
      batchAddNum(e,i){
        this.batchNum[i] = e.target.value
      },
       batchInsert() {
        this.batchLen++;
      },

      weekDel( item, i, j){
       console.log(item)
       let del= item.time_range.findIndex((v,index)=>{
          if(index == j){
            return true
          }
       })
        item.time_range.splice(del,1)
         this.weekArr[i] = item;
        this.weekObj = this.weekArr;
      },
      weekAddTime(e, item, i, j,m) {
       //半全场 半场特殊处理
       if(m!=undefined){
          item.time_range[j][m].time = e
       }else{
          item.time_range[j].time = e
       }
        this.weekArr[i] = item;
        this.weekObj = this.weekArr;
      },
      weekAddAmount(e, item, i, j,m) {
       if(m!=undefined){
          item.time_range[j][m].price = e.target.value
       }else{
         item.time_range[j].price = e.target.value
       }
        this.weekArr[i] = item;
        this.weekObj = this.weekArr;
      },
      weekAddNum(e, item, i, j,m) {
       if(m!=undefined){
          item.time_range[j][m].num = e.target.value
       }else{
         item.time_range[j].num = e.target.value
       }
        this.weekArr[i] = item;
        this.weekObj = this.weekArr;
      },

      hoverTab() {
        // this.batchLen = 1;
        // this.batchTime = [];
        // this.batchAmount = [];

        // if(this.weekObj[name]!=undefined){
        //   this.weekArr = this.weekObj[name];
        // }else{
        //   this.weekArr = this.returnWeekArr();
        // }

      },
      //批量设置
      batchSet() {


          this.weekArr = this.returnWeekArr();//解决重复数据处理
          // console.log( this.batchTime)
          for (var i in this.weekArr) {

            this.batchTime.forEach((value, j) => {
              let data = {
                time: value,
                price: this.batchAmount[j],
                num:this.batchNum[j]
              }
              //   let data1 = [];
              // this.checkboxVeneuModel.forEach((ve,je)=>{
              //   let data2 =   {
              //          time:value,
              //          price:this.batchAmount[j],
              //          veneu_model:ve
              //       }
              //     data1.push(data2);

              //   })

              if (this.weekArr[i] != undefined) {

                this.weekArr[i].time_range.push(data);
              }

            })
          }


        this.weekObj = this.weekArr
        console.log(434343,this.weekObj)

      },



    }

  }
</script>

<style lang="scss">
  @import "./index";
</style>
